<!DOCTYPE html>
<html>
<head>
    <meta charset="utf-8">
    <title>编辑商品</title>
    <meta name="renderer" content="webkit">
    <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
    <meta name="viewport" content="width=device-width, initial-scale=1.0, minimum-scale=1.0, maximum-scale=1.0, user-scalable=0">
    <link rel="stylesheet" href="/Application/iframe/assets/libs/layuiadmin/layui/css/layui.css"/>
    <link rel="stylesheet" href="/Application/iframe/assets/libs/layuiadmin/style/admin.css" media="all">
    <link rel="stylesheet" href="/Application/iframe/assets/libs/layuiadmin/style/mylay.css" media="all">
    <style type="text/css">
        html {background: #fff;padding-top: 20px;}
    </style>
    <style type="text/css">
        .uploader-list {
            margin-left: -15px;
        }
 
        .uploader-list .info {
            position: relative;
            margin-top: -25px;
            background-color: black;
            color: white;
            filter: alpha(Opacity=80);
            -moz-opacity: 0.5;
            opacity: 0.5;
            width: 100px;
            height: 25px;
            text-align: center;
            display: none;
        }
 
        .uploader-list .handle {
            position: relative;
            background-color: black;
            color: white;
            filter: alpha(Opacity=80);
            -moz-opacity: 0.5;
            opacity: 0.5;
            width: 100px;
            text-align: right;
            height: 18px;
            margin-bottom: -18px;
            display: none;
        }
 
        .uploader-list .handle span {
            margin-right: 5px;
        }
 
        .uploader-list .handle span:hover {
            cursor: pointer;
        }
 
        .uploader-list .file-iteme {
            margin: 12px 0 0 15px;
            padding: 1px;
            float: left;
        }
    </style>
</head>
<body>
<div class="layui-form">
    <input type="hidden" name="id" value="{$goods.id}">
    <div class="layui-form-item">
        <label class="layui-form-label"><span>*</span> 商品名称</label>
        <div class="layui-input-inline">
            <input type="text" name="title" lay-verify="required" placeholder="请输入商品名称" autocomplete="off" class="layui-input" value="{$goods.title}">
        </div>
        <div class="layui-form-mid layui-word-aux"></div>
    </div>

    <div class="layui-form-item">
        <label class="layui-form-label">缩略图</label>
        <div class="layui-input-inline">
            <input type="text" id="m_pic" name="m_pic" value="{$goods.m_pic}"  lay-verify="required" placeholder="请上传图片" autocomplete="off" class="layui-input">
        </div>
        <button class="layui-btn" type="button" id="btn_upload">上传</button>
    </div>
    <div class="layui-form-item">
        <label class="layui-form-label"> 商品图片</label>
        <div class="layui-input-inline">
            <blockquote class="layui-elem-quote layui-quote-nm" style="margin-top: 10px;">
                预览图：
                <div class="layui-upload-list" id="demo2">
                    <?php
                        $thumb = explode(',',$goods['thumb']);
                        foreach($thumb as $k => $v){
                    ?>
                        <img src="<?php echo $v?>">
                    <?php }?>
                    
                </div>
                <input type="hidden" id="thumb" name="thumb" value="{$goods.thumb}"   autocomplete="off" class="layui-input">
             </blockquote>
        </div>
        
         <button type="button" class="layui-btn" id="test2">多图片上传</button> 
    </div>

    <div class="layui-form-item">
        <label class="layui-form-label">所属分类</label>
        <div class="layui-input-inline">
            <select name="class_id" lay-filter="m_type">
                <volist name="class_data" id="vo">
                    <option value="{$vo.id}" {if $goods['class_id'] == $vo['id'] } selected {/if} >{$vo.class_name}</option>
                </volist>
                

            </select>
        </div>
    </div>
    

    
    <div class="layui-form-item">
        <label class="layui-form-label">所属规格</label>
        <div class="layui-input-block">
            <volist name="spec" id="v">
                <div>
                    <if condition="$v['level'] == '1'" >{$v.spec_name}:</if>
                   <?php foreach($v['child'] as $k => $vo){ ?>

                         <input type="checkbox" class="spec" name="spec_id[]" <?php if( in_array($vo['id'],explode(',',$goods['spec_id'])) ){?> checked <?php }?>  value="{$vo.id}" title="{$vo.spec_name}">
                    
                      <?php  }?>
                </div>
            </volist> 
         
        
        
            <input type="hidden" name="spec_id" value="" id="spec_id">
        </div>
    </div>
    
     <div class="layui-form-item">
        <label class="layui-form-label">所属榜单</label>
        <div class="layui-input-inline">
            <select name="a_class" lay-filter="a_class">
                <option value="0" <?php if($goods['a_class'] == '0' ){ ?> selected <?php }?> >选择所属榜单</option>
                <option value="1" <?php if($goods['a_class'] == '1' ){ ?> selected <?php }?>>限时秒杀</option>
                <option value="2" <?php if($goods['a_class'] == '2' ){ ?> selected <?php }?>>逛好店</option>
                <option value="3" <?php if($goods['a_class'] == '3' ){ ?> selected <?php }?>>热销榜</option>
                <option value="4" <?php if($goods['a_class'] == '4' ){ ?> selected <?php }?>>便宜好货</option>
            </select>
        </div>
    </div>
    
    <div class="layui-form-item" id="seckill" <?php if($goods['a_class'] != '1' ){ ?>style="display:none" <?php }?> >
        <label class="layui-form-label">秒杀时段</label>
        <div class="layui-input-inline">
            <select name="seckill_id" lay-filter="m_type" >
                <volist name="seckill" id="vo">
                    <option value="{$vo.id}" <?php if($goods['seckill_id'] == $vo['id'] ){ ?> selected <?php }?>>{$vo.start_time}</option>
                </volist>
            </select>
        </div>
    </div>
    
    <div class="layui-form-item">
        <label class="layui-form-label"><span>*</span> 商品内容</label>

        <div class="layui-input-block">
          <textarea name="content" placeholder="请输入内容" class="layui-textarea">{$goods.content}</textarea>
        </div>
        <div class="layui-form-mid layui-word-aux"></div>
    </div>
    
    <div class="layui-form-item">
        <label class="layui-form-label"><span>*</span>当前价格</label>
        <div class="layui-input-inline">
            <input type="text" name="old_price" value="{$goods.old_price}"  placeholder="请输入当前价格" autocomplete="off" class="layui-input">
        </div>
        <div class="layui-form-mid layui-word-aux"></div>
    </div>
    
    <div class="layui-form-item">
        <label class="layui-form-label"><span>*</span>优惠价格</label>
        <div class="layui-input-inline">
            <input type="text" name="new_price" value="{$goods.new_price}"  placeholder="请输入优惠价格" autocomplete="off" class="layui-input">
        </div>
        <div class="layui-form-mid layui-word-aux"></div>
    </div>
    
    <div class="layui-form-item">
        <label class="layui-form-label"><span>*</span> 邮费</label>
        <div class="layui-input-inline">
            <input type="text" name="postage" value="{$goods.postage}"  placeholder="请输入邮费" autocomplete="off" class="layui-input">
        </div>
        <div class="layui-form-mid layui-word-aux"></div>
    </div>
    
     <div class="layui-form-item">
        <label class="layui-form-label"><span>*</span> 库存</label>
        <div class="layui-input-inline">
            <input type="text" name="inventory" value="{$goods.inventory}" placeholder="请输入库存" autocomplete="off" class="layui-input">
        </div>
        <div class="layui-form-mid layui-word-aux"></div>
    </div>
    <div class="layui-form-item">
        <label class="layui-form-label"> 排序</label>
        <div class="layui-input-inline">
            <input type="text" name="sort" value="{$goods.sort}"  placeholder="请输入排序" autocomplete="off" class="layui-input">
        </div>
        <div class="layui-form-mid layui-word-aux"></div>
    </div>

  
    <div class="layui-form-item layui-hide">
        <input type="button" lay-submit lay-filter="LAY-submit" id="LAY-submit" value="确认">
    </div>
</div>
<script src="http://ajax.aspnetcdn.com/ajax/jquery/jquery-2.1.4.min.js"></script>
<script type="text/javascript" src="/Application/iframe/assets/libs/layuiadmin/layui/layui.js"></script>

<script>
    layui.config({
        base: '/Application/iframe/assets/libs/layuiadmin/'
    }).extend({
        index: 'lib/index'
    }).use(['index', 'form', 'upload'], function(){
        var $ = layui.$
            ,upload = layui.upload
            ,form = layui.form;
        //上传
    
        //多图片上传
        //多图片上传
          upload.render({
            elem: '#test2'
            ,url: "{:U('Merchant/upload/uploadFile')}" //改成您自己的上传接口
            ,multiple: true
            ,before: function(obj){
              //预读本地文件示例，不支持ie8
              obj.preview(function(index, file, result){
                  
                $('#demo2').append('<img src="'+ result +'" alt="'+ file.name +'" class="layui-upload-img">')
              });
            }
            ,done: function(res){
              //上传完毕
                console.log(res);
                if(res.code ==  '1001'){
                    $("#thumb").val($("#thumb").val()+res.src+',')
                    
                    
                }
                
            }
          });
          upload.render({
            elem: '#btn_upload'
            ,url: "{:U('upload/uploadFile')}"
            ,data: {dir: 'coupon'}
            ,accept: 'images'
            ,before: function () {
                layer.load();
            }
            ,done: function(res){
                layer.closeAll();
                if(res.code == 1001) {
                    $('#m_pic').val(res.src);
                    $('#yl_pic').attr('src',res.src);
                }
                else {
                    layer.msg(res.msg);
                }
            }
            ,error: function(){
                layer.closeAll();
                layer.msg('请求异常');
            }
        });
          
   
            
          
          
          
          
           form.on('select(a_class)', function(data){
			if(data.value == 1){
				$("#seckill").css("display","block");
				form.render('select');
			}else{
			    	$("#seckill").css("display","none");
				form.render('select');
			}
		});

    })
    $("#LAY-submit").click(function(){
        var arr = new Array();
   
         $("input:checkbox[name='spec_id[]']:checked").each(function(i){
            arr[i] = $(this).val();
        });
        var arrData = arr.join(",");
        $("#spec_id").val(arrData);
        console.log(arrData);
  
        
    })
    
    
    
        
      //data.field.like = arr.join(",");//将数组合并成字符串
</script>
</body>
</html>